@extends('admin.layouts')
@section('css')
    <link href="{{asset('assets/css/bootstrap.min.css')}}" rel="stylesheet" />
    <link rel="stylesheet" href="{{asset('assets/css/font-awesome.min.css')}}" />
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />

    <!-- ace styles -->

    <link rel="stylesheet" href="{{asset('assets/css/ace.min.css')}}" />
    <link rel="stylesheet" href="{{asset('assets/css/ace-rtl.min.css')}}" />
    <link rel="stylesheet" href="{{asset('assets/css/ace-skins.min.css')}}" />
    <script src="{{asset('assets/js/ace-extra.min.js')}}"></script>
@endsection
@section('content')
    <div class="main-content">
        <div class="breadcrumbs" id="breadcrumbs">
            <script type="text/javascript">
                try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
            </script>

            <ul class="breadcrumb">
                <li>
                    <i class="icon-home home-icon"></i>
                    <a href="{{url('admin/index')}}">主页</a>
                </li>

                <li>
                    <a>分类</a>
                </li>
                <li class="active">
                    @if($type==1)
                        文章分类
                        @elseif($type==2)
                    图片分类
                        @else
                    视频分类
                        @endif
                </li>
            </ul><!-- .breadcrumb -->

            <div class="nav-search" id="nav-search">
                <form class="form-search">
								<span class="input-icon">
									<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
									<i class="icon-search nav-search-icon"></i>
								</span>
                </form>
            </div><!-- #nav-search -->
        </div>

        <div class="page-content">
            <div class="page-header">
                <h1>
                    分类管理
                    <small>
                        <i class="icon-double-angle-right"></i>
                        @if($type==1)
                            文章分类
                        @elseif($type==2)
                            图片分类
                        @else
                            视频分类
                        @endif
                    </small>
                </h1>
            </div><!-- /.page-header -->
            <!-- 模态框（Modal） -->
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">添加分类</h4>
                        </div>
                        <form id="cate">
                            <div class="modal-body">
                                <div class="row">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 分类名</label>
                                        <div class="col-sm-6">
                                            <input type="text" id="form-field-1" name="category" placeholder="分类名" class="col-xs-10 col-sm-10" />
                                        </div>

                                        <div class="col-xs-4">
                                            <label class="inline">
                                                <input type="checkbox" class="ace ace-checkbox-2" id="status" name="status" checked="checked"/>
                                                <span class="lbl"> 启用</span>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <input type="submit" class="btn btn-primary" value="提交">
                            </div>
                        </form>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>

            {{--xiugai--}}
                    <!-- 模态框（Modal） -->
            <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">修改分类</h4>
                        </div>
                        <form id="updatecate">
                            <div class="modal-body">
                                <div class="row">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 分类名</label>
                                        <div class="col-sm-6">
                                            <input type="text" id="catename" name="category" placeholder="分类名" class="col-xs-10 col-sm-10" />
                                        </div>

                                        <div class="col-xs-4">
                                            <label class="inline">
                                                <input type="hidden" name="id" id="id" value="">
                                                <input type="checkbox" class="ace ace-checkbox-2" id="statuss" name="status"/>
                                                <span class="lbl"> 启用</span>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <input type="submit" class="btn btn-primary" value="更新">
                            </div>
                        </form>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->

                    <div class="row">
                        <div class="col-xs-12">
                            <button class="btn btn-success" data-toggle="modal" data-target="#myModal">添加分类</button>
                            <hr>
                            <div class="table-responsive">
                                <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>分类名</th>
                                        <th>
                                            <i class="icon-time bigger-110 hidden-480"></i>
                                            创建时间
                                        </th>
                                        <th>
                                            <i class="icon-time bigger-110 hidden-480"></i>
                                            更新时间
                                        </th>
                                        <th class="hidden-480">状态</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>

                                    <tbody>
                                    @if(sizeof($categories)>0)
                                    @foreach($categories as $cate)
                                    <tr id="id{{$cate['id']}}">
                                        <td>
                                            {{$cate['id']}}
                                        </td>
                                        <td>{{$cate['category']}}</td>
                                        <td>{{date('Y-m-d H:i:s',$cate['created_at'])}}</td>
                                        <td>{{date('Y-m-d H:i:s',$cate['updated_at'])}}</td>

                                        <td class="hidden-480">
                                            @if($cate['status']==1)
                                            <span class="label label-sm label-success">
                                                <i class="icon-ok bigger-120"></i>可用
                                            </span>
                                            @else
                                                <span class="label label-sm label-danger">
                                                <i class="icon-remove bigger-120"></i>停用
                                            </span>
                                                    @endif

                                        </td>

                                        <td>
                                            <div class="visible-md visible-lg hidden-sm hidden-xs btn-group">
                                                @if($cate['status']==0)
                                                <a class="btn btn-xs btn-success" onclick="upstatus({{$cate['id']}},{{$cate['status']}})">
                                                    <i class="icon-ok bigger-120"></i>
                                                </a>
                                                @else
                                                <a class="btn btn-xs btn-danger"  onclick="upstatus({{$cate['id']}},{{$cate['status']}})">
                                                    <i class="icon-remove bigger-120"></i>
                                                </a>
                                                @endif

                                                <a class="btn btn-xs btn-info" onclick="update({{$cate['id']}},{{$cate['status']}})">
                                                    <i class="icon-edit bigger-120"></i>
                                                </a>

                                                <a class="btn btn-xs btn-danger" onclick="deletec({{$cate['id']}})">
                                                    <i class="icon-trash bigger-120"></i>
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                        @endforeach
                                    @else
                                        <tr>
                                            <td style="text-align: center" colspan="11">什么都没有啦</td>
                                        </tr>
                                    @endif
                                    </tbody>
                                </table>
                            </div><!-- /.table-responsive -->
                        </div><!-- /span -->
                    </div><!-- /row -->

                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.page-content -->
    </div><!-- /.main-content -->
    @endsection
@section('javascript')
    <script src='{{asset('assets/js/jquery-2.0.3.min.js')}}'></script>
    <script src="{{asset('assets/js/bootstrap.min.js')}}"></script>
    <script src="{{asset('assets/js/typeahead-bs2.min.js')}}"></script>

    <!-- ace scripts -->
    <script type="text/javascript" src="{{asset('assets/layer/layer.js')}}"></script>
    <script src="{{asset('assets/js/ace-elements.min.js')}}"></script>
    <script src="{{asset('assets/js/ace.min.js')}}"></script>
    <script>
        $("#cate").submit(function(){
            var category=$("#form-field-1").val();
            var status=$("#status").is(':checked')?1:0;
            if(category==''){
                layer.msg('分类名不能为空');
            }else{
                layer.load(2);
                $.post('{{url('admin/addcategory')}}',{'type':{{$type}},'category':category,'status':status,'_token':'{{csrf_token()}}'},function(res){
                    layer.closeAll('loading');
                    if(res.status){
                        layer.msg(res.msg);
                        location.reload(true);
                    }else{
                        layer.msg(res.msg);
                    }
                });
            }
            return false;
        });

        $("#updatecate").submit(function(){
            var category=$("#catename").val();
            var status=$("#statuss").is(':checked')?1:0;
            if(category==''){
                layer.msg('分类名不能为空');
            }else{
                layer.load(2);
                $.post('{{url('admin/updatecategory')}}',{'type':{{$type}},'id':$('#id').val(),'category':category,'status':status,'_token':'{{csrf_token()}}'},function(res){
                    layer.closeAll('loading');
                    if(res.status){
                        layer.msg(res.msg);
                        location.reload(true);
                    }else{
                        layer.msg(res.msg);
                    }
                });
            }
            return false;
        });

        function upstatus(id,status){
            layer.load(2);
            $.post('{{url('admin/updatecategorystatus')}}',{'_token':'{{csrf_token()}}','id':id,'status':status},function(res){
                layer.closeAll('loading');
                if(res.status){
                    layer.msg(res.msg);
                    location.reload(true);
                }else{
                    layer.msg(res.msg);
                }
            });
        }

        function deletec(id){
            layer.confirm('你确定要删除吗？',{
                btn:['确定','取消']
            },function(){
                layer.load(2);
                $.post('{{url('admin/deletecategory')}}',{'_token':'{{csrf_token()}}','id':id}, function (res) {
                    layer.closeAll('loading');
                    if(res.status){
                        $("#id"+id).remove();
                        layer.msg(res.msg);
                    }else{
                        layer.msg(res.msg);
                    }
                });
            },function(){

            });
        }

        function update(id,status){
            $("#catename").val($.trim($("#id"+id).find(':nth-child(2)').text()));
            if(status){
                $("#statuss").attr('checked','checked');
            }
            $("#id").val(id);
            $('#myModal1').modal('show');
        }
    </script>
    @endsection